﻿//------------------------------------------------------------------------------
// <copyright file="RpcRemoteMethodNotFoundException.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

namespace Microsoft.Internal.GamesTest.Rpc.Client
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    /// <summary>
    /// An exception type that represents the user trying to invoke a remote method that doesn't exist.
    /// </summary>
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors", Justification = "Want to strongly encourage users of this class to include the name of the remote method that could not be found.")]
    [Serializable]
    public class RpcRemoteMethodNotFoundException : RpcException
    {
        /// <summary>
        /// Initializes a new instance of the RpcRemoteMethodNotFoundException class.
        /// </summary>
        public RpcRemoteMethodNotFoundException()
        {
        }

        /// <summary>
        /// Initializes a new instance of the RpcRemoteMethodNotFoundException class.
        /// </summary>
        /// <param name="message">The message describing the purpose for throwing this exception.</param>
        public RpcRemoteMethodNotFoundException(string message)
            : base(message)
        {
        }

        /// <summary>
        /// Initializes a new instance of the RpcRemoteMethodNotFoundException class.
        /// </summary>
        /// <param name="message">The message describing the purpose for throwing this exception.</param>
        /// <param name="methodName">The name of the method that could not be found.</param>
        public RpcRemoteMethodNotFoundException(string message, string methodName)
            : base(message)
        {
            this.MethodName = methodName;
        }

        /// <summary>
        /// Initializes a new instance of the RpcRemoteMethodNotFoundException class.
        /// </summary>
        /// <param name="message">The message describing the purpose for throwing this exception.</param>
        /// <param name="methodName">The name of the method that could not be found.</param>
        /// <param name="inner">Any applicable inner exception.</param>
        public RpcRemoteMethodNotFoundException(string message, string methodName, Exception inner)
            : base(message, inner)
        {
            this.MethodName = methodName;
        }

        /// <summary>
        /// Initializes a new instance of the RpcRemoteMethodNotFoundException class.
        /// </summary>
        /// <param name="info">The SerializationInfo for this exception.</param>
        /// <param name="context">The StreamingContext for this exception.</param>
        protected RpcRemoteMethodNotFoundException(
          System.Runtime.Serialization.SerializationInfo info,
          System.Runtime.Serialization.StreamingContext context)
            : base(info, context)
        {
            this.MethodName = info.GetString("MethodName");
        }

        /// <summary>
        /// Gets the name of the remote Rpc method that could not be found.
        /// </summary>
        public string MethodName { get; private set; }

        /// <summary>
        /// Serializes this exception.
        /// </summary>
        /// <param name="info">The SerializationInfo for this exception.</param>
        /// <param name="context">The StreamingContext for this exception.</param>
        public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            base.GetObjectData(info, context);

            info.AddValue("MethodName", this.MethodName);
        }
    }
}
